package com.example.library_core

import com.example.library_core.ext.fromJson
import com.example.library_core.ext.toJson
import com.example.library_core.utils.GsonUtils
import com.google.gson.GsonBuilder
import org.junit.Test

import org.junit.Assert.*

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }
    @Test
    fun gsonTest(){
        val json  = "{\"name\":\"苏亮\",\"age\":33,\"number\":9527}"
        val gson1 = GsonBuilder().create();
        val gson2 = GsonBuilder().serializeNulls().create()
        val gsonObject1 : GsonObject = gson1.fromJson(json,GsonObject::class.java)
        val gsonObject2 : GsonObject = gson2.fromJson(json,GsonObject::class.java)
        val toJson = gsonObject1.toJson()       //{"name":"苏亮","age":33,"addressCode":null,"number":9527}
        val toJson1 = gson1.toJson(gsonObject1)  // {"name":"苏亮","age":33,"number":9527}
        val toJson2 = gson2.toJson(gsonObject2)   // {"name":"苏亮","age":33,"addressCode":null,"number":9527}
        println("")
    }


    data class GsonObject(val name : String,val age : Int){
        var addressCode : String? = null
        var number : Int = 0
    }
}